********************************************************************************
*
**#	Fig 4.A: Judge FE: DiD 	
*
********************************************************************************	

use "${DATA}/data_DV.dta", clear

eststo clear 

cap drop j_* 
cap drop dj_* 
cap drop perc_* 

/* dummy for judges */

tab judge, gen(j_) 
	
/* interacting (judge X DV_case) */ 

forval j = 1/12 {	
	gen dj_`j' = j_`j'*dv_case
} 

	la var dj_1  "Brown"
	la var dj_2  "Dumas"
	la var dj_3  "Eisenstein"
	la var dj_4  "Evans"
	la var dj_5  "Faimon"
	la var dj_6  "Fishburn"
	la var dj_7  "Higgins"
	la var dj_8  "Holt"
	la var dj_9  "Mondelli"
	la var dj_10 "Moreland"
	la var dj_11 "Robinson"
	la var dj_12 "Ruben"

/* controls -  without judge characteristics */ 

local cntrl_def "i.white c.age i.prev_court_dv i.prev_court prev_court_num c.charge_count"

eststo clear 

/* diff-in-diff regression: Reg Guilty Judge(j) DV_case (Judge(j) X DV_case) */

forval j = 1/12 {	
				
	eststo judge_`j': reghdfe guilty_case dj_`j' j_`j' dv_case `cntrl_def', $hdfe_opts	
	
	/* calculating the percentage effect compared to mean */	
		
		estadd ysumm 
		
		gen perc_`j' = string(abs(round((_b[dj_`j']/e(ymean))*100),0.1))
		
		replace perc_`j' = "("+perc_`j'+"%)" 
}

# d ;

/* graph label options */

local opt 
		"mlcolor(black) 
		mfcolor(gray)
		mlabel mlabcolor(black)  
		mlabposition(12) 
		mlabgap(*2) 
		mlcolor(black) 
		msize(medsmall)"
	;
	

coefplot
	(judge_11, 	mlabel(perc_11)	`opt')
	(judge_2, 	mlabel(perc_2)	`opt')
	(judge_10, 	mlabel(perc_10)	`opt')
	(judge_8, 	mlabel(perc_8)	`opt') 
	(judge_1, 	mlabel(perc_1)	`opt')
	(judge_3, 	mlabel(perc_3)	`opt')
	(judge_4, 	mlabel(perc_4)	`opt')
	(judge_5, 	mlabel(perc_5)	`opt') 
	(judge_6, 	mlabel(perc_6)	`opt')
	(judge_7, 	mlabel(perc_7)	`opt')
	(judge_9, 	mlabel(perc_9)	`opt')
	(judge_12, 	mlabel(perc_12)	`opt')  
	,
	keep(dj_*) 
	xline(
		0, lpattern(dot) lc(black))
	xtitle(
		"Estimated {&delta}{sup:did}", margin(0 0 0 2) )
	xscale(
		range(-0.25 0.25))
	yscale(lstyle(none))
	yla(, notick) 
	xlab(
		-0.2 "-0.2pp" -0.1 "-0.1pp" 0 "0" .1 "+0.1pp" 0.2 "+0.2pp",labsize(medsmall))
	grid(none)
	title(
		"Court Specific Fixed Effects"
		"Outtcome = Conviction"
		, size(medium) justification(left) bexpand) 
	note(
		"<- Less likely to convict"
		"(Percentage change from baseline in parentheses)", 
		size(small))
	ciopts(
		recast(rcap) lpattern(dash) lwidth(thin) lcolor(black*0.7) )  
	headings(
		dj_11 = "{bf:DV Court:}"           
      dj_10 = "{bf:OP Docket:}"   
      dj_1 = "{bf:General Court:}")	
	nokey
	plotlabels(black)
	offset(0)
	aspectratio(2.3) 
	xsize(12) ysize(20)
	name(jfe, replace) ;
	
# d cr

graph save "${OUTPUT}/fig4A.gph", replace 


********************************************************************************
*
**#	Fig 4.B: One Judge at a time being excluded: DiD 
*		
********************************************************************************

eststo clear 

cap drop j_* 

cap drop perc_* 

tab judge, gen(j_)
	label variable j_1  "Brown"
	label variable j_2  "Dumas"
	label variable j_3  "Eisenstein"
	label variable j_4  "Evans"	
	label variable j_5  "Faimon"
	label variable j_6  "Fishburn"
	label variable j_7  "Higgins"
	label variable j_8  "Holt"
	label variable j_9  "Mondelli"
	label variable j_10 "Moreland"
	label variable j_11 "Robinson"
	label variable j_12 "Ruben"

foreach j of numlist 1 3 4 5 6 7 8 9 10 12 {			
 	
	eststo dd_judge_`j': ///
	reghdfe guilty_case dv_did dv_case dv_judge $cntrls if j_`j'==0, $hdfe_opts 
	
	/* calculating the pct effect rel to mean */	
	
		estadd ysumm 
		
		gen perc_`j' = string(abs(round((_b[dv_did]/e(ymean))*100),0.1))
		
		replace perc_`j' = "("+perc_`j'+"%)" 
}

/* graph label options */

# d ;

local opt 
		"mlcolor(black) 
		mfcolor(gray)
		mlabel 
		mlabcolor(black) 
		mlabposition(12) 
		mlabgap(*2) 
		mlcolor(black) 
		msize(medsmall)"	
		;

coefplot
	(dd_judge_10, mlabel(perc_10)	`opt' rename(dv_did ="-(Moreland)"))
	(dd_judge_8,  mlabel(perc_8)	`opt' rename(dv_did = "-(Holt)")) 
	(dd_judge_1,  mlabel(perc_1)	`opt' rename(dv_did = "-(Brown)"))
	(dd_judge_3,  mlabel(perc_3)	`opt' rename(dv_did = "-(Eisenstein)"))
	(dd_judge_4,  mlabel(perc_4)	`opt' rename(dv_did = "-(Evans)"))
	(dd_judge_5,  mlabel(perc_5)	`opt' rename(dv_did = "-(Faimon)"))
	(dd_judge_6,  mlabel(perc_6)	`opt' rename(dv_did = "-(Fishburn)"))
	(dd_judge_7,  mlabel(perc_7)	`opt' rename(dv_did = "-(Higgins)"	))
	(dd_judge_9,  mlabel(perc_9)	`opt' rename(dv_did = "-(Mondelli)"))
	(dd_judge_12, mlabel(perc_12)	`opt' rename(dv_did = "-(Ruben)"))   
	,
	keep(dv_did)     
	xline(
		0, lpattern(dot) lc(black))
	xtitle(
		"Estimated {&delta}{sup:did} ", margin(0 0 0 2))
	xscale(
		range(-0.22 0.22))
	xlab(
		-0.2 "-0.2pp" -0.1 "-0.1pp" 0 "0" .1 "+0.1pp" 0.2 "+0.2pp",labsize(medsmall)) 
	grid(none)	
	yscale(lstyle(none))
	yla(, notick) 
	title(
		"Estimated Effect of DV Court when"
		"one Non-DV Court is Excluded"
		, size(medium) justification(left)  bexpand) 
	note(
		"<- Less likely to convict"
		"(Percentage change from baseline in parentheses)", 
		size(small))
	ciopts(
		recast(rcap) lpattern(dash) lwidth(thin) lcolor(black))  
	nokey 
	plotlabels(black)
	offset(0)
	aspectratio(2.2)				
	xsize(12) ysize(20)
	name(jex, replace) ;
	
# d cr 

graph save "${OUTPUT}/fig4B.gph", replace 
